package com.ids.transfer;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ids.transfer.config.DatasourceConfig;
import com.ids.transfer.config.ItemConfig;
import com.ids.transfer.config.TaskConfig;
import com.ids.transfer.data.XmlParse;


/**
 * this abstract class read init information from XML File,include task info,the
 * implement classes of task's info and the params info of the class.
 * like the Requst
 */
public abstract class AbstractExtraTask {
	
	protected final Log logger = LogFactory.getLog(getClass());

	private ExtraParam ep;

	/**
	 * 返回参数实例
	 * @param taskid
	 * @return <i>EtraParam</i>
	 */
	public ExtraParam readXmlInfo(String taskid) {
		try {
			//先不初始化task
			HashMap<String,HashMap<String,IExtra>> tasks
				= new HashMap<String,HashMap<String,IExtra>>();
			//数据源
			DatasourceConfig srcDsc, desDsc;
			// 任务配置
			TaskConfig tc = new TaskConfig(taskid);
			//items
			HashMap<String,ItemConfig> items
			=new HashMap<String,ItemConfig>();

			// 收集必要的数据源信息
			srcDsc = new DatasourceConfig(tc.getSrcds());
			desDsc = new DatasourceConfig(tc.getDesds());
			// 收集任务对应的实现类信息
			HashMap<String,String> map=tc.getEcmap();
			
			//初始化实现类
			for (String key : map.keySet()) {
				items.put(map.get(key), new ItemConfig(map.get(key)));
			}

			HashMap<String, String> taskMap=null;
			try {
				taskMap = XmlParse.getAllTaskId();
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			if (ep == null)
				ep = new ExtraParam();
			ep.addParam(ExtraParam.SRCDSC, srcDsc);
			ep.addParam(ExtraParam.DESDSC, desDsc);
			ep.addParam(ExtraParam.ITEMS, items);
			ep.addParam(ExtraParam.TASKCONFIG, tc);
			return ep;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 执行抽取
	 */
	public void execute() {

	}
	
}